package pres.moling.common.tool;

import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;

public interface Asserts {

    static <T> void isNull(T obj, Consumer<T> consumer) {
        isNull(obj);
        consumer.accept(obj);
    }

    static <T, R> R isNull(T obj, Function<T, R> function) {
        isNull(obj);
        return function.apply(obj);
    }

    private static void isNull(Object object) {
        if (Objects.isNull(object)) {
            throw new RuntimeException();
        }
    }

    static void isNull(Object obj, String errCode, String msg) {
        isTrue(Objects.isNull(obj), errCode, msg);
    }

    static void isTrue(boolean condition, String errCode, String msg) {
        if (condition) {
            throw new RuntimeException();
        }
    }

    static void isFalse(boolean condition, String errCode, String msg) {
        if (!condition) {
            throw new RuntimeException();
        }
    }

}
